/*
 * This file is part of Cockpit.
 *
 * Copyright (C) 2013 Red Hat, Inc.
 *
 * Cockpit is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * Cockpit is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Cockpit; If not, see <https://www.gnu.org/licenses/>.
 */

/* ---------------------------------------------------------------------------------------------------- */

@use "page";
@use "table";
@use "nav";
@import "@patternfly/patternfly/components/Select/select.css";
@import "@patternfly/patternfly/utilities/Text/text.css";
@import "@patternfly/patternfly/components/Icon/icon.css";

:root {
  --ct-color-host-accent: var(--pf-v5-global--active-color--100);
  --ct-topnav-background: var(--pf-v5-global--BackgroundColor--dark-100);
}

#shell {
    block-size: 100%;
}

.pf-v5-theme-dark {
  --ct-topnav-background: var(--pf-v5-global--BackgroundColor--dark-200);
}

/* Hacks on top for now */

html.index-page body {
  overflow: hidden;
}

#machine-change-auth > p {
  margin-block-end: 5px;
}

// Fix fingerprint layout
.add-host-fingerprint {
  margin-block-start: var(--pf-v5-global--spacer--md);

  td {
    padding: 0;
    line-height: inherit;
    block-size: auto;
    vertical-align: middle !important;

    &:first-child {
      padding-inline-end: var(--pf-v5-global--spacer--md);
    }
  }
}

.machine-key {
  margin: 0;
  white-space: pre-line;
  padding-block: var(--pf-v5-global--spacer--xs);
  padding-inline: var(--pf-v5-global--spacer--sm);
}

.login-setup-checkbox-wrapper {
  // Use a flex layout to better vertically align the contents to the grid
  display: flex;
}

#edit-machine-port {
  inline-size: 100px;
}

#connecting {
  block-size: 100%;
  background-color: var(--ct-global--palette--black-250);
  text-align: center;
  padding-block-start: 120px;
}

/* System information */

#systime-date-input,
#systime-time-hours,
#systime-time-minutes {
  display: inline;
}

/* index page */

.display-language-modal {
  /* Do not let the language menu expand to the end of the page */
  .pf-v5-c-menu__content {
    max-block-size: 20rem;
    overflow: auto;
  }
}

iframe.container-frame {
  border: none;
  inline-size: 100%;
}

// Page layout

$phone: 767px;
$desktop: $phone + 1px;

.page {
  --nav-width: 15rem;
  display: grid;
  inline-size: 100%;
  block-size: 100%;

  // Set masthead and toolbar to transparent, so the background shows through
  // (including the accent line)

  .pf-v5-c-masthead {
    --pf-v5-c-masthead--BackgroundColor: transparent;
  }

  .pf-v5-c-toolbar {
    --pf-v5-c-toolbar--BackgroundColor: transparent;
  }

  @media (max-width: $phone) {
    grid-template-areas: "main main main" "sidebar switcher header";
    grid-template-rows: 1fr 4rem;
    grid-template-columns: 1fr auto auto;
    overflow: hidden;

    .area-ct-subnav {
      grid-area: main;
    }

    .sidebar-toggle {
      grid-area: sidebar;
      display: flex;
      background: var(--pf-v5-global--BackgroundColor--dark-100);
    }

    > .header,
    > .navbar,
    > .sidebar-toggle {
      // Line on bottom, Base color (with subtle glow)
      background: linear-gradient(
        to top,
        var(--ct-color-host-accent),
        var(--ct-color-host-accent) 0.1875rem,
        transparent 0.1875rem
      ),
        linear-gradient(
        to top,
        var(--ct-color-host-accent) -1.5rem,
        var(--ct-topnav-background) 0.75rem
      );
    }

    // Remove excess padding from masthead in mobile
    .pf-v5-c-masthead {
      --pf-v5-c-masthead--inset: 0;
    }
  }

  @media (min-width: $desktop) {
    grid-template-areas: "switcher header" "sidebar main";
    grid-template-rows: max-content 1fr;
    grid-template-columns: minmax(min-content, var(--nav-width)) 1fr;

    > .navbar {
      max-inline-size: var(--nav-width);
    }

    .sidebar {
      grid-area: sidebar;
    }

    .sidebar-toggle {
      grid-area: none;
      display: none;
    }

    > .header {
      // Shadow to the left, Line on top, Base color (with subtle glow)
      background: linear-gradient(
        to right,
        var(--ct-topnav-background) -1rem,
        transparent 1rem
      ),
        linear-gradient(
        to bottom,
        var(--ct-color-host-accent),
        var(--ct-color-host-accent) 0.1875rem,
        transparent 0.1875rem
      ),
        linear-gradient(
        to bottom,
        var(--ct-color-host-accent) -1.5rem,
        var(--ct-topnav-background) 0.75rem
      );
    }
  }

  // Shrink nav for VMs @ 1024×768 (and below)
  @media (max-width: 1024px) and (max-height: 768px) and (orientation: landscape) {
    --nav-width: 14rem;
  }

  .area-ct-content {
    grid-area: main;
  }

  .header {
    grid-area: header;
  }
}

.hostkey-type {
  font-size: small;
}

.hostkey-verify-help {
  margin-block-end: 1.5em;
}

/* Alert fixups */
.modal-content .pf-v5-c-alert {
  text-align: start;
  margin-block-end: 24px;
}

.early-failure {
  block-size: 100%;
}

// Header menu buttons don't need a background color (especially in dark mode)
.pf-v5-c-toolbar .pf-v5-c-dropdown__toggle {
  --pf-v5-c-dropdown__toggle--BackgroundColor: transparent;
}

// Header menu buttons don't need a background color (especially in dark mode)
.pf-v5-c-toolbar .pf-v5-c-dropdown__toggle {
  --pf-v5-c-dropdown__toggle--BackgroundColor: transparent;
}

// PF hardcodes header colors to dark, which does funky things
// ...so swap them back properly for dropdown menus
.pf-v5-c-masthead .pf-v5-c-dropdown__menu {
  --pf-v5-global--BackgroundColor--100: var(--pf-v5-global--BackgroundColor--light-100);
  --pf-v5-global--Color--100: var(--pf-v5-global--Color--dark-100);
}

// Customize the about screen with the Cockpit logo
.pf-v5-c-about-modal-box {
  --pf-v5-c-about-modal-box--BackgroundImage: linear-gradient(#000d, #000d), url(../shell/images/cockpit-icon.svg);
  --pf-v5-c-about-modal-box--BackgroundPosition: max(25rem, 143%) 10rem;
  --pf-v5-c-about-modal-box--BackgroundSize--min-width: 786px;

  [dir="rtl"] {
    --pf-v5-c-about-modal-box--BackgroundPosition: calc(100% - 30rem) 10rem;
  }
}
